/*
 * (C) APUE
 * Show an un-reentrant function --- getpwnam
 */
#include "apue.h"
#include <pwd.h>

static void my_alarm(int signo)
{
	struct passwd *rootptr;
	printf("in signal handler...\n");
	if ((rootptr = getpwnam("root")) == NULL)
		err_quit("getpwnam(root) error");
	alarm(1);	/* produce SIGALRM every one second */
}

int main()
{
	struct passwd *passwdptr;
	if (signal(SIGALRM, my_alarm) == SIG_ERR)
		err_quit("signal handler set error");
	alarm(1);
	while (1)
	{
		if ((passwdptr = getpwnam("sheng")) == NULL)
			err_quit("getpwnam error");
		if (strcmp("sheng", passwdptr->pw_name) != 0)
			printf("return value corrupted! pw_name = %s\n", passwdptr->pw_name);
	}
}
